﻿package com.tudou.home.model.ad
{
    import com.tudou.ad.events.*;
    import com.tudou.ad.view.*;
    import com.tudou.home.commands.ad.*;
    import com.tudou.home.model.ad.base.*;

    public class AdBackProxy extends AdVideoProxyBase
    {
        private var V2_TIMEOUT:int = 2000;
        public static const NAME:String = "AdBakcProxy";

        public function AdBackProxy()
        {
            super(NAME);
            return;
        }// end function

        override protected function viewEventHlr(event:AdItemViewEvent) : void
        {
            switch(event.type)
            {
                case AdItemViewEvent.SHOW_START:
                {
                    sendNotification(AdBackCommandSet.SHOW_START);
                    break;
                }
                case AdItemViewEvent.SHOW_END:
                {
                    sendNotification(AdBackCommandSet.SHOW_END);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        override protected function adErrorEnd() : void
        {
            sendNotification(AdBackCommandSet.ERROR_END);
            return;
        }// end function

        override protected function frontStuffComplete() : void
        {
            prepareToShow();
            return;
        }// end function

        override public function startView() : void
        {
            if (!startViewCommon())
            {
                return;
            }
            view = new AdBackView();
            startViewFronts();
            if (!view)
            {
                return;
            }
            loadBg();
            return;
        }// end function

        override protected function adV2End() : void
        {
            loadedV2 = true;
            prepareToShow();
            return;
        }// end function

        override protected function delayTimerComplete() : void
        {
            v2Timeout = V2_TIMEOUT;
            loadV2();
            return;
        }// end function

        public function startAdBack() : void
        {
            loadFront();
            return;
        }// end function

        override protected function frontStuffError() : void
        {
            adSkip();
            adErrorEnd();
            return;
        }// end function

        private function prepareToShow() : void
        {
            if (loaded && loadedV2)
            {
                sendNotification(AdBackCommandSet.PREPARE_TO_SHOW);
            }
            return;
        }// end function

    }
}
